package com.xuzimian.globaldemo.rpc.webservice;

import com.xuzimian.globaldemo.rpc.webservice.client.HelloServiceImplService;
import com.xuzimian.globaldemo.rpc.webservice.service.HelloServiceImpl;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import javax.xml.ws.Endpoint;
import java.io.IOException;

/**
 * @program: global-demo
 * @description:
 * @author: xzm
 * @create: 2019-01-10 11:32
 **/
public class WebServiceDemo {


    /**
     * 运行该方法发布一个webservice后，在浏览器中输入http://localhost:8080/helloService?wsdl
     * 获取到webservice服务接口的xml，
     * 方案1：使用IDE(eclipse或idea)工具命令生成客户端: 用 http://localhost:8080/helloService?wsdl 文档地址 在指定目录中生成调用webservice的接口
     * 方案2：通过 "wsimport"（JDK自带）命令生成客户端代码。进入命令行模式，执行 wsimport -s . http://localhost:9000/HelloWorld?wsdl，就会在当前目录下生成客户端代码。
     * @throws IOException
     */
    @BeforeEach
    public void publishWebService() throws IOException, InterruptedException {
        //create and publish an endPoint
        HelloServiceImpl hello = new HelloServiceImpl();
        Endpoint endPoint = Endpoint.publish("http://localhost:8080/helloService", hello);
        System.out.println("server is running");
    }

    /**
     * 该测试方法中调用的类都是利用idea工具自动生成webservice客户端代码
     * @throws IOException
     * @throws InterruptedException
     */
    @Test
    public void callWebService() throws IOException, InterruptedException {
        HelloServiceImplService serviceImplService = new HelloServiceImplService();
        com.xuzimian.globaldemo.rpc.webservice.client.HelloServiceImpl service
                = serviceImplService.getHelloServiceImplPort();
       System.out.println(service.sayHello("hao do you do?"));
       System.in.read();
    }

}
